package com.fit.pages.product;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.UserAccess;
import com.fit.dao.product.ProductDAO;
import com.fit.dao.user.UserDAO;
import com.fit.entities.Sold_product;
import com.fit.entities.Product;
import com.fit.entities.User;

@AdminAccess
@UserAccess
public class Details {

	@Property
	@Persist
	private Product product;
	
	@Property
	@Persist
	private Sold_product bill;
	
	@Property
	@Persist
	private Long id;
	
	@Inject
	private ProductDAO productDAO;
	
	public boolean isManufacturerNotNull(){
		if(product.getManufacturer()!=null){
			return true;
		} else {
			return false;
		}
	}
	
	public boolean itemsNotNull(){
		if(product.getTotal_sold()!=null){
			return true;
		} else {
			return false;
		}
	}
	
	
	public boolean itemsNull(){
		if(product.getTotal_sold()==null){
			return false;
		} else {
			return true;
		}
	}
	
	Object onActivate(Long id) {
		product = productDAO.findById(id);
	
		return null;

	}
	
	public double add(){
		double l;
		
		l = product.getTotal_sold()*product.getPrice();
		
		return l;
	}
	
	public double sum(){
		double l;
		l = (product.getItems_left()+product.getTotal_sold())*product.getPrice();
		return l;
	}
	
	


}
